package com.madixin.madichat.data.api

import com.madixin.madichat.data.model.LoginRequest
import com.madixin.madichat.data.model.ApiResponse
import com.madixin.madichat.data.model.ChatSessionResponse
import com.madixin.madichat.data.model.MessageResponse
import com.madixin.madichat.data.model.UpdateSessionRequest
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.http.*

interface ApiService {
    @POST("/chat-api/login")
    suspend fun login(@Body request: LoginRequest): ApiResponse<String>
    
    @GET("/chat-api/chatsession")
    suspend fun getChatSessions(
        @Header("Authorization") token: String,
        @Query("page") page: Int = 1,
        @Query("pageSize") pageSize: Int = 20
    ): ApiResponse<List<ChatSessionResponse>>
    
    @GET("/chat-api/chatsession/{sessionId}/message")
    suspend fun getSessionMessages(
        @Header("Authorization") token: String,
        @Path("sessionId") sessionId: String,
        @Query("page") page: Int = 0,
        @Query("size") size: Int = 50
    ): ApiResponse<List<MessageResponse>>
    
    @DELETE("/chat-api/chatsession/{sessionId}")
    suspend fun deleteSession(
        @Header("Authorization") token: String,
        @Path("sessionId") sessionId: String
    ): ApiResponse<Any>
    
    // 添加更新会话标题的接口
    @PUT("/chat-api/chatsession/{sessionId}")
    suspend fun updateSessionTitle(
        @Header("Authorization") token: String,
        @Path("sessionId") sessionId: String,
        @Body request: UpdateSessionRequest
    ): ApiResponse<Any>
    
    
    @Streaming
    @POST("/chat-api/chat/message")
    @Multipart
    suspend fun sendMessage(
        @Header("Authorization") token: String,
        @Part("sessionId") sessionId: RequestBody,
        @Part("content") content: RequestBody,
        @Part("type") type: RequestBody,
        @Part image: MultipartBody.Part? = null,
        @Part("options") options: RequestBody? = null
    ): ResponseBody
}